import QtQuick 1.0
import com.nokia.symbian 1.0
import "../js/Storage.js" as Storage
import "../delegate"

PurePage {
    id: favoritePage

    anchors { fill: parent; topMargin: statusBar.height; bottomMargin: toolBar.height }
    signal downloadFav
    signal removeFav(int index)

    function checkFav(count) {
        if (count != 0) {
            noFavData.visible = false
        } else {
            noFavData.visible = true
        }
    }

    ListModel {
        id: favModel

    }

    LodingIndicator {
        id: lodingFavPage

    }

    ListView {
        id: favListView

        anchors { fill: parent}
        cacheBuffer: 2 * height
        delegate: FavoriteDelegate {}
        model: favModel
    }

    Text {
        id: noFavData

        anchors.centerIn: parent
        text: "NO FAVORITE SESSION(S)"
        color: "#636363"

        font.pixelSize: 25
        font.wordSpacing: 2
        font.family: "Helvetica"
        smooth: true
    }

    onDownloadFav: {
        favModel.clear();
        Storage.getFavoriteCache(favModel);
        checkFav(favModel.count);
    }

    onRemoveFav: {
        favModel.remove(index);
        checkFav(favModel.count);
    }




}
